package com.ruoyi.wechat.api;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.domain.Order;
import com.ruoyi.system.service.IOrderService;
import com.ruoyi.wechat.controller.QRCodeController;
//import com.ruoyi.wechat.service.impl.QRCodeGenerator;
import com.ruoyi.wechat.service.impl.QRCodeGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/wx/order")
public class WxOrderController {
    @Autowired
    private IOrderService orderService;
//    @Autowired
//    private QRCodeGenerator qrCodeGenerator;
//    @Autowired
//    private QRCodeController qrCodeController;
@Autowired
private QRCodeGenerator qrCodeGenerator;


private RestTemplate restTemplate = new RestTemplate();

//    // 使用RestTemplate来发送请求
//    private final RestTemplate restTemplate;

//    // 构造函数注入RestTemplate
//    public ControllerA(RestTemplate restTemplate) {
//        this.restTemplate = restTemplate;
//    }


//    @Autowired
//    private QRCodeGenerator qrCodeGenerator;

    /**
     * 查询订单表列表
     */
//    @PreAuthorize("@ss.hasPermi('camp:order:list')")
    @GetMapping("/list")
    public AjaxResult list(Order order)
    {
        System.out.println("order1111111111111:------"+order);
        List<Order> list = orderService.selectOrderList(order);
        System.out.println("wkylist:-----"+list);
        return AjaxResult.success(list);
    }

    /**
     * 新增订单表
     */

    @PostMapping
    public AjaxResult add(@RequestBody Order order)
    {

        order.setOrderTime(new Date());

        order.setOrderId(IdUtils.randomUUID());
        String text=order.getOrderId();
        System.out.println("order123123123:"+order);
        orderService.insertOrder(order);
       String id= order.getOrderId();

return AjaxResult.success(id);
    }

//根据订单id修改订单的图片和状态改为2
@PutMapping
public AjaxResult edit(@RequestBody Order order)
{
    long id=2;
    order.setStatus(id);
    System.out.println("order22222222222222222:"+order);
    return AjaxResult.success(orderService.updateOrder(order));
}




//    @Log(title = "营地订单", businessType = BusinessType.UPDATE)
//    扫一扫修改状态为3
    @PutMapping("/update")
    public AjaxResult edit1(@RequestBody Order order)
    {
        System.out.println("order22222:"+order);

        return AjaxResult.success(orderService.updateOrder(order));
    }



}
